<template>
  <el-card shadow="never">
    <e-table
      ref="eTable"
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :total="total"
    >
      <el-table-column label="规则运行开始时间" slot="startTime" align="center">
        <template slot-scope="scope">{{ formatTime(scope.row.startTime, 'seconds') }}</template>
      </el-table-column>
      <el-table-column label="规则运行结束时间" slot="endTime" align="center">
        <template slot-scope="scope">{{ formatTime(scope.row.endTime, 'seconds') }}</template>
      </el-table-column>
    </e-table>
  </el-card>
</template>

<script>
import { logPage } from '@/api/prewarning'
export default {
  data() {
    return {
      total: 1,
      loading: false,
      tableData: [],
      columns: [
        {
          label: '预警规则名',
          prop: 'ruleName'
        },
        {
          slot: 'startTime'
        },
        {
          slot: 'endTime'
        },
        {
          label: '规则耗时(秒)',
          prop: 'mistiming'
        },
        {
          label: '产生预警数据(条)',
          prop: 'dataNum'
        },
        {
          label: '下次运行时间',
          prop: 'nextRunTime'
        }
      ],
      queryParam: {
        pageSize: 10,
        pageNo: 1
      }
    }
  },
  mounted() {
    this.handleGetList()
  },
  methods: {
    //columns 动态删减，根据form传递过来的数据
    async handleGetList(param = {}) {
      this.loading = true
      this.queryParam = Object.assign(this.queryParam, param)
      const res = await logPage(this.queryParam)
      if (res && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>
